package com.adeng.springbootdemo.config;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.beans.BeansException;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

/**
 * @author hzwengcheng 2018-05-06 23:03
 */
@ImportResource("classpath:applicationContext.xml")
@Configuration
public class HystrixConfiguration implements ApplicationContextAware {

    private ApplicationContext applicationContext;


    //注册Hystrix框架的拦截器，使得框架的注解能够生效
//    @Bean
////    @Order(100)
//    public HystrixCommandAspect hystrixAspect() {
//        return new HystrixCommandAspect();
//    }

    //注入servlet,拦截url="/hystrix.stream"
    //测试git dev commit
    @Bean
    public ServletRegistrationBean hystrixMetricsStreamServlet() {
        System.out.print("++++++++++++++***************");
        ServletRegistrationBean registration = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
        registration.addUrlMappings("/hystrix.stream");
        return registration;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
